package com.crayon2f.test;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.crayon2f.test.beans.Book;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.time.LocalDate;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;

/**
 * Created by feifan.gou@gmail.com on 2024/3/11 15:25.
 */
public class TEST2024_03 {

    @Test
    public void testStreamSort() {

        List<Book> list = Lists.newArrayList(
                new Book(3),
                new Book(1),
                new Book(3),
                new Book(4),
                new Book(5),
                new Book(2),
                new Book(55),
                new Book(6),
                new Book(7),
                new Book(8),
                new Book(9)
        );

        list.stream().sorted(Comparator.comparing(Book::getPageNumber)).peek(book -> {
            Integer pageNumber = book.getPageNumber();
            List<List<String>> lists = Lists.newArrayList();
            for (int i = 0; i < pageNumber; i++) {
                lists.add(new ArrayList<>());
            }
            book.setList(lists);
        }).forEach(book -> {
            System.out.println(book.getList().size());
        });
    }

    @Test
    public void testLocalDateMinus() {

        LocalDate localDate = LocalDate.now().plusDays(10);
        LocalDate lastYear = localDate.withYear(2023);
        System.out.println(localDate);
        System.out.println(lastYear);

        System.out.println(Month.DECEMBER.plus(1));
        System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL, Locale.CHINA));
        System.out.println(Month.DECEMBER.toString());

        System.out.printf("today is %s\n", LocalDate.now());


        String string = "44";
        System.out.println(Arrays.toString(string.split("(,)")));

        String regex = "([-+]?\\d+(\\.\\d+)?)";

        System.out.println("99".matches(regex));
        System.out.println("99.07".matches(regex));
        System.out.println("99.99".matches(regex));
        System.out.println("-99.09".matches(regex));
        System.out.println("0.88".matches(regex));
        System.out.println("-0.7799".matches(regex));

    }
}
